# -*- coding: utf-8 -*-

from PySide.QtGui import *
from PySide.QtCore import *
import sys

QTextCodec.setCodecForTr(QTextCodec.codecForName("utf8"))
class MoreDialog(QDialog):
    def __init__(self,parent=None):
        super(MoreDialog,self).__init__(parent)

        self.setWindowTitle(u"更多的消息对话框")
        self.labelTxt=QLabel("About Qt MessageBox")

        questionButton=QPushButton("question")
        infoButton=QPushButton("Information")
        warningButton=QPushButton("warning")
        criticalButton=QPushButton("critical")
        aboutButton=QPushButton("about")
        aboutQtButton=QPushButton("About Qt")
        customButton=QPushButton("customer")


        gridLayout=QGridLayout(self)
        gridLayout.addWidget(self.labelTxt,0,0,1,2)
        gridLayout.addWidget(questionButton,1,0)
        gridLayout.addWidget(infoButton,1,1)
        gridLayout.addWidget(warningButton,2,0)
        gridLayout.addWidget(criticalButton,2,1)
        gridLayout.addWidget(aboutButton,3,0)
        gridLayout.addWidget(aboutQtButton,3,1)
        gridLayout.addWidget(customButton,4,0)

        self.setLayout(gridLayout)

        self.connect(questionButton,SIGNAL("clicked()"),self.slotQuestionFunc)
        self.connect(infoButton,SIGNAL("clicked()"),self.slotInfoFunc)
        self.connect(warningButton,SIGNAL("clicked()"),self.slotWarnFunc)
        self.connect(criticalButton,SIGNAL("clicked()"),self.slotCirticalFunc)
        self.connect(aboutButton,SIGNAL("clicked()"),self.slotAboutFunc)
        self.connect(aboutQtButton,SIGNAL("clicked()"),self.slotAboutQtFunc)
        self.connect(customButton,SIGNAL("clicked()"),self.slotCustomFunc)

    def slotQuestionFunc(self):
        button=QMessageBox.question(self,"question",
                                    self.tr("您好，再见~"),
                                    QMessageBox.Ok | QMessageBox.Cancel,
                                    QMessageBox.Ok)
        if button == QMessageBox.Ok :
            self.labelTxt.setText(u"好的")
        elif button == QMessageBox.Cancel:
            self.labelTxt.setText(u"再见")
        else:
            return

    def slotInfoFunc(self):
        QMessageBox.information(self,
                                "Information",
                                self.tr("您好啊~~"))
        self.labelTxt.setText("嘿，您好啊~")

    def slotWarnFunc(self):
        button=QMessageBox.warning(self,
                                   "Warning",
                                   self.tr("您是否要保存？"),
                                   QMessageBox.Save | QMessageBox.Discard | QMessageBox.Cancel,
                                   QMessageBox.Save)
        if button == QMessageBox.Save:
            self.labelTxt.setText("QMessageBox.Save")
        elif button == QMessageBox.Discard:
            self.labelTxt.setText("QMessageBox.Discard")
        elif button == QMessageBox.Cancel:
            self.labelTxt.setText("QMessageBox.Cancel")
        else:
            self.labelTxt.setText("其他操作")

    def slotCirticalFunc(self):
        QMessageBox.critical(self,
                             "critical",
                             self.tr("程序发现一个致命的错误"))
        self.labelTxt.setText("Critical")

    def slotAboutFunc(self):
        QMessageBox.about(self,"About",self.tr("About 事例"))
        self.labelTxt.setText("About MessageBox")

    def slotAboutQtFunc(self):
        QMessageBox.aboutQt(self,"About Qt")
        self.labelTxt.setText("About Qt")

    def slotCustomFunc(self):
        customMsgBox=QMessageBox(self)
        customMsgBox.setWindowTitle("Custom message box")
        lockButton=customMsgBox.addButton(self.tr("锁定"),
                                          QMessageBox.ActionRole)
        unlockButton=customMsgBox.addButton(self.tr("解锁"),
                                            QMessageBox.ActionRole)
        cancelButton=customMsgBox.addButton("cancel",
                                            QMessageBox.ActionRole)
        customMsgBox.setText(self.tr("这是一个自定义消息框！"))
        customMsgBox.exec_()
        button=customMsgBox.clickedButton()
        if button == lockButton:
            self.labelTxt.setText("Custom MessageBox/Lock")
        elif button == unlockButton:
            self.labelTxt.setText("Custom MessageBox/Unlock")
        elif button == cancelButton:
            self.labelTxt.setText("Custom MessageBox/Cancel")

if __name__ =="__main__":
    app= QApplication(sys.argv)
    moreDialog=MoreDialog()
    moreDialog.show()
    sys.exit(app.exec_())